package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseCategoryTrademark;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.model.product.CategoryTrademarkVo;
import com.atguigu.gmall.product.service.BaseCategoryTrademarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product/baseCategoryTrademark")
public class BaseCategoryTrademarkController {

    @Autowired
    private BaseCategoryTrademarkService baseCategoryTrademarkService;

    //根据三级分类id查询出分类品牌
    @GetMapping("/findTrademarkList/{category3Id}")
    public Result findTrademarkList(@PathVariable Long category3Id){
      List<BaseTrademark> baseTrademarkList =baseCategoryTrademarkService.findTrademarkList(category3Id);
        return Result.ok(baseTrademarkList);
    }

    //添加分类品牌的信息回显，就是显示当前还没添加的品牌
    @GetMapping("findCurrentTrademarkList/{category3Id}")
    public Result findCurrentTrademarkList(@PathVariable Long category3Id){
        List<BaseTrademark> baseTrademarkList =baseCategoryTrademarkService.findCurrentTrademarkList(category3Id);
        return Result.ok(baseTrademarkList);
    }
    //添加品牌
    @PostMapping("/save")
    public Result saveBaseTrademark(@RequestBody CategoryTrademarkVo categoryTrademarkVo){
        baseCategoryTrademarkService.saveBaseTrademark(categoryTrademarkVo);
        return Result.ok();
    }
    //删除品牌
    @DeleteMapping("/remove/{category3Id}/{trademarkId}")
    public Result removeBaseTrademark(@PathVariable Long category3Id,
                                      @PathVariable Long trademarkId){

        baseCategoryTrademarkService.removeBaseTrademark(category3Id,trademarkId);
        return Result.ok();
    }
}
